// File Name: led_init.c
// Author: kukukukuku~
// Date: 2024-12-24

#include "apm32f00x_gpio.h"
#include "apm32f00x_misc.h"
#include "apm32f00x_tmr1.h"
#include "./LED/inc/led_init.h"
#include "./LED/inc/led_macros.h"

/**
 * @brief   LED GPIO配置
 * @param   None
 * @retval  None
 * @note    静态
*/
static void led_gpio_config(void)
{
    GPIO_Config_T gpioConfig = 
    {
        .pin   = LED_GPIO_PIN,
        .mode  = GPIO_MODE_OUT_PP,
        .speed = GPIO_SPEED_10MHz,
        .intEn = GPIO_EINT_DISABLE,
    };
    
    GPIO_Config(LED_GPIO_PORT, &gpioConfig);
}


/**
 * @brief   LED TMR1配置
 * @param   None
 * @retval  None
 * @note    静态
*/
static void led_tmr1_config(void)
{
    TMR1_TimeBaseConfig_T timeBaseConfig = 
    {
        .cntMode         = TMR1_CNT_MODE_UP,
        .count           = LED_TMR_PR,
        .divider         = LED_TMR_PSC,
        .repetitionCount = 0,
    };
    
    //Key TMR1初始化
    TMR1_Reset(LED_TMR);
    TMR1_ConfigTimerBase(LED_TMR, &timeBaseConfig);
    TMR1_EnableAutoReloadBuffer(LED_TMR);
    TMR1_ClearStatusFlag(LED_TMR, TMR1_FLAG_UPDATE);
    TMR1_EnableInterrupt(LED_TMR, TMR1_INT_UPDATE);
    NVIC_EnableIRQRequest(LED_TMR_IRQ, 0);
    TMR1_Enable(LED_TMR);
}


/**
 * @brief   LED初始化
 * @param   None
 * @retval  None
 * @note    None
*/
void led_init(void)
{
    led_gpio_config();
    led_tmr1_config();
}
